package com.itheima.web;

import com.itheima.dbservice.UserService;
import com.itheima.pojo.UserInfo;
import com.itheima.servcie.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/users")
public class UsersController {
    @Autowired
    private UsersService usersService;
    @Autowired
    private BlackListService blackListService;
    @Autowired
    private SettingService settingService;
    @Autowired
    private QuestionService questionService;
     @Autowired
    private UserLikeService userLikeService;
    @Autowired
    private UsersService userService;


    /**
     * 是否已喜欢
     * @param uid
     * @return
     */
    @GetMapping("/{uid}/alreadyLove")
    public ResponseEntity alreadyLove(@PathVariable Long uid){
        return ResponseEntity.ok(usersService.isAlreadyLove(uid));
    }

    /**
     * 获取黑名单
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("blacklist")
    public ResponseEntity getBlackList(@RequestParam(defaultValue = "1")Integer page,
                                       @RequestParam(defaultValue = "10")Integer pagesize){
        return blackListService.getBlackList(page,pagesize);
    }
    /**
     * 黑名单 -移除
     */
    @DeleteMapping("/blacklist/{uid}")
    public ResponseEntity removeBlackList(@PathVariable("uid") Long blackUserId){
        return blackListService.removeBlackList(blackUserId);
    }

    /**
     * 设置陌生人问题 - 保存
     */
    @PostMapping("questions")
    public ResponseEntity addQuestion(@RequestBody Map<String,String> map){
        return questionService.addQuestion(map.get("content"));
    }

    /**
     * 粉丝 - 喜欢
     */
    @PostMapping("fans/{uid}")
    public ResponseEntity getFans(@PathVariable("uid") Long id){
        return userLikeService.addUserLike(id);
    }

    /**
     * 用户通用设置 - 读取
     */
    @GetMapping("settings")
    public ResponseEntity getSettingsMessage(){
        return userService.getSettingsMessage();
    }

    /**
     * 通知设置 -保存
     */
    @PostMapping("notifications/setting")
    public ResponseEntity notice(@RequestBody Map<String,Boolean> map){
        return settingService.settingNotice(map);
    }

    /**
     * 用户资料 - 读取
     */
    @GetMapping
    public ResponseEntity getUserInfo(Long userID){
        return userService.getUserInfo(userID);
    }


    /**
     * 用户资料 - 更新头像
     */
    @PostMapping("header")
    public ResponseEntity updateAvatar(@RequestBody MultipartFile headPhoto){
        return userService.updateAvatar(headPhoto);
    }

    /**
     * 用户资料 - 保存
     */
    @PutMapping
    public ResponseEntity saveUserInfo(@RequestBody UserInfo userInfo){
        return userService.saveUserInfo(userInfo);
    }

    /**
     * 喜欢 - 取消
     */
    @DeleteMapping("like/{uid}")
    public ResponseEntity deleteUserLike(@PathVariable Long uid){
        return userLikeService.deleteUserLike(uid);
    }

    /**
     * 发送短信验证码
     */
    @PostMapping("phone/sendVerificationCode")
    public ResponseEntity sendMessage(){
        return userService.sendMessage();
    }

    /**
     * 修改手机号 - 2 校验验证码
     */
    @PostMapping("phone/checkVerificationCode")
    public ResponseEntity checkCode(@RequestBody String verificationCode){
        return userService.checkCode(verificationCode);
    }

    /**
     * 修改手机号 - 3 保存
     */
    @PostMapping("phone")
    public ResponseEntity saveChangePhone(@RequestBody Map<String,String> map){
        return userService.saveChangePhone(map.get("phone"));
    }
    /**
     * 互相喜欢，喜欢，粉丝 - 统计
     */
    @GetMapping("counts")
    public ResponseEntity totalCount(){
        return userLikeService.getTotalCount();
    }


    /**
     * 互相喜欢、喜欢、粉丝、谁看过我 - 翻页列表
     */
    @GetMapping("friends/{type}")
    public ResponseEntity pageList(@PathVariable Integer type,
                                   @RequestParam(defaultValue = "1")Integer page,
                                   @RequestParam(defaultValue = "10")Integer pagesize,
                                   String nickname){
        return userLikeService.pageList(type,page,pagesize,nickname);
    }




}
